/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.CustomerIOTRPortal;

import session.TX.StakeholderAccountsSBRemote;
import Helper.Helper_Outlet;
import Helper.Helper_Stakeholder_Food;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author Lu Xiaodi
 */
@ManagedBean(name = "reservationSearchManagedBean")
@SessionScoped
public class ReservationSearchMB {

    @EJB
    StakeholderAccountsSBRemote stakeholderBean;
    @ManagedProperty(value = "#{tableBookingMB}")
    private TableBookingMB tableBookingMB;
    String stakeholderStr;
    Helper_Stakeholder_Food aStakeholder;
    List<Helper_Stakeholder_Food> stakeholders;
    List<Helper_Stakeholder_Food> suggestionStakeholders;

    /** Creates a new instance of ReservationSearchMB */
    public ReservationSearchMB() {
    }

    public List<Helper_Stakeholder_Food> completeStakeholderSelection(String query) {
        if (stakeholders == null) {
            stakeholders = getAllFoodStakeholders();
        }
        suggestionStakeholders = new ArrayList<Helper_Stakeholder_Food>();
        for (Helper_Stakeholder_Food s : stakeholders) {
            if (s.getName().toLowerCase().contains(query.toLowerCase())) {
                suggestionStakeholders.add(s);
            }
        }
        return suggestionStakeholders;
    }

    public List<Helper_Outlet> getOutletsByStakeholder() {
        if (stakeholderStr == null) {
            return null;
        }
        return stakeholderBean.getOutletsByStakeholder(stakeholderStr);
    }

    public String getStakeholderStr() {
        return stakeholderStr;
    }

    public void setStakeholderStr(String stakeholderStr) {
        this.stakeholderStr = stakeholderStr;
    }

    public List<Helper_Stakeholder_Food> getStakeholders() {
        return stakeholders;
    }

    public void setStakeholders(List<Helper_Stakeholder_Food> stakeholders) {
        this.stakeholders = stakeholders;
    }

    public List<Helper_Stakeholder_Food> getSuggestionStakeholders() {
        return suggestionStakeholders;
    }

    public void setSuggestionStakeholders(List<Helper_Stakeholder_Food> suggestionStakeholders) {
        this.suggestionStakeholders = suggestionStakeholders;
    }

    public List<Helper_Stakeholder_Food> getAllFoodStakeholders() {
        return stakeholderBean.getAllStakeholderFoodHelper();
    }

    public Helper_Stakeholder_Food getaStakeholder() {
        return aStakeholder;
    }

    public void setaStakeholder(Helper_Stakeholder_Food aStakeholder) {
        this.aStakeholder = aStakeholder;
    }

    public TableBookingMB getTableBookingMB() {
        return tableBookingMB;
    }

    public void setTableBookingMB(TableBookingMB tableBookingMB) {
        this.tableBookingMB = tableBookingMB;
    }
    
    public void onRowSelect(SelectEvent event) {
	 Helper_Outlet out = (Helper_Outlet) event.getObject();
         tableBookingMB.setOutletId(out.getId());
    }
}
